package com.sumer.psychology.common.domain.model;

import java.io.Serializable;

/**
 * 作者
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/8/12
 * Time: 13:37
 */
public class Author implements Serializable {
    private String identity;
    private String name;

    public Author() {
    }

    public Author(String identity, String name) {
        this.identity = identity;
        this.name = name;
    }

    public static Author fromUser(User aUser) {
        return new Author(aUser.identity(), aUser.name());
    }

    public Author(String identity) {
        this.identity = identity;
    }

    public String identity() {
        return identity;
    }

    public String name() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Author author = (Author) o;

        if (identity != null ? !identity.equals(author.identity) : author.identity != null) return false;
        if (name != null ? !name.equals(author.name) : author.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = identity != null ? identity.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Author{" +
                "identity='" + identity + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
